using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace GodSoft.Models.Mapping
{
    public class ActionInfoMap : EntityTypeConfiguration<ActionInfo>
    {
        public ActionInfoMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.RequestUrl)
                .IsRequired()
                .HasMaxLength(256);

            this.Property(t => t.RequestHttpType)
                .IsRequired()
                .HasMaxLength(16);

            this.Property(t => t.ActionName)
                .IsRequired()
                .HasMaxLength(16);

            this.Property(t => t.Describe)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("ActionInfo");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.ParentID).HasColumnName("ParentID");
            this.Property(t => t.RequestUrl).HasColumnName("RequestUrl");
            this.Property(t => t.RequestHttpType).HasColumnName("RequestHttpType");
            this.Property(t => t.ActionName).HasColumnName("ActionName");
            this.Property(t => t.SubTime).HasColumnName("SubTime");
            this.Property(t => t.ActionType).HasColumnName("ActionType");
            this.Property(t => t.Describe).HasColumnName("Describe");
            this.Property(t => t.DelFlag).HasColumnName("DelFlag");

            // Relationships
            this.HasMany(t => t.Roles)
                .WithMany(t => t.ActionInfoes)
                .Map(m =>
                    {
                        m.ToTable("ActionInfoRole");
                        m.MapLeftKey("ActionInfo_ID");
                        m.MapRightKey("Role_ID");
                    });


        }
    }
}
